<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form
            ref="form"
            :inline="false"
            :model="form"
            label-width="80px"
            size="normal"
        >
            <el-card :body-style="{ padding: '20px' }" shadow="never">
                <div slot="header">轮播管理</div>
                <el-form-item label="标题">
                    <el-input v-model="form.title"></el-input>
                    <hd-error name="title"/>
                </el-form-item>
                <el-form-item label="上传图片">
                    <hd-image v-model="form.image"></hd-image>
                    <hd-error name="image"/>
                </el-form-item>
                <el-form-item label="跳转链接">
                    <el-input
                        v-model="form.url"
                        placeholder="跳转链接"
                    ></el-input>
                    <hd-error name="url"/>
                </el-form-item>

                <el-button type="primary" @click="onSubmit">提交</el-button>
            </el-card>
        </el-form>
    </div>
</template>

<script>
import tabs from "./tabs";

export default {
    route: false,
    props: ["id"],
    data() {
        return {
            tabs,
            form: {},
            sid: this.$route.params.id,
        };
    },
    async created() {
        if (this.id) {
            this.form = await this.axios.get(`admin/swiper/${this.sid}`);
        }
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/swiper/${this.id}` : `admin/swiper`
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: "admin.swiper.index"});
        },
    },
};
</script>

<style>
</style>
